/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EscenariosVista.java
 *
 * Created on Feb 7, 2011, 1:08:02 AM
 */

package com.teg.vista;

import com.teg.dominio.EscenarioPrueba;
import com.teg.dominio.Metodo;
import java.util.ArrayList;


/**
 *
 * @author danielbello
 */
public class EscenariosVista extends javax.swing.JDialog {

   

    private java.util.ArrayList<EscenarioPrueba> escenariosMetodos;

    /** Creates new form EscenariosVista */
    public EscenariosVista(java.awt.Frame parent, boolean modal, java.util.ArrayList<EscenarioPrueba> escenarios) {
        super(parent, modal);

        initComponents();

        this.escenariosMetodos = escenarios;

        ArrayList<String> nombres = new ArrayList<String>();

        for (EscenarioPrueba escenario : escenarios) {
            nombres.add(escenario.getNombre());
        }

        listaSeleccion.setListData(nombres.toArray());

      
    }

   

    /*private void setEscenarios(){

        listaEscenarios = new javax.swing.JList();

        listaMetodos = new javax.swing.JList();

        scrollEscenarios.setViewportView(listaEscenarios);

        scrollMetodos.setViewportView(listaMetodos);

        java.util.ArrayList<String> nombreEscenarios = new java.util.ArrayList<String>();

        for (EscenarioPrueba escenario : escenariosMetodos) {

            nombreEscenarios.add(escenario.getNombre());
        }

        listaEscenarios.setListData(nombreEscenarios.toArray());

        listaEscenarios.addMouseListener(new java.awt.event.MouseAdapter(){

            public void MouseClicked(java.awt.event.MouseEvent e){

                String nombre = (String) listaEscenarios.getSelectedValue();

                java.util.ArrayList<Metodo> metodos = new java.util.ArrayList<Metodo>();

                for (EscenarioPrueba escenario : escenariosMetodos) {

                    if (escenario.getNombre().equals(nombre)){
                        metodos.addAll(escenario.getMetodos());
                    }

                }

                listaMetodos.setListData(metodos.toArray());

            }
        });

    }*/


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        scrollMetodos = new javax.swing.JScrollPane();
        listaMetodos = new javax.swing.JList();
        scrollEscenarios = new javax.swing.JScrollPane();
        listaSeleccion = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Vista Escenarios de Prueba");

        jButton1.setText("Ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        scrollMetodos.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Metodos de Escenario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 12))); // NOI18N

        scrollMetodos.setViewportView(listaMetodos);

        scrollEscenarios.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Escenarios de Prueba", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 12))); // NOI18N

        listaSeleccion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaSeleccionMouseClicked(evt);
            }
        });
        scrollEscenarios.setViewportView(listaSeleccion);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(scrollEscenarios, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                        .add(18, 18, 18)
                        .add(scrollMetodos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 238, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, scrollEscenarios, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, scrollMetodos, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
                .add(18, 18, 18)
                .add(jButton1)
                .add(17, 17, 17))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void listaSeleccionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaSeleccionMouseClicked
        // TODO add your handling code here:

                String nombre = (String) listaSeleccion.getSelectedValue();

                java.util.ArrayList<Metodo> metodos = new java.util.ArrayList<Metodo>();

                for (EscenarioPrueba escenario : escenariosMetodos) {

                    if (escenario.getNombre().equals(nombre)){
                        metodos.addAll(escenario.getMetodos());
                    }

                }

                ArrayList<String> nombresMetodos = new ArrayList<String>();

                for (Metodo metodo : metodos) {

                    nombresMetodos.add(metodo.getNombre());
        }

                listaMetodos.setListData(nombresMetodos.toArray());


    }//GEN-LAST:event_listaSeleccionMouseClicked

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JList listaMetodos;
    private javax.swing.JList listaSeleccion;
    private javax.swing.JScrollPane scrollEscenarios;
    private javax.swing.JScrollPane scrollMetodos;
    // End of variables declaration//GEN-END:variables

}
